Total images after deduplication: 70
Families: ["Asilidae", "Bibionidae", "Ceratopogonidae", "Chironomidae", "Rhagionidae", "Sciaridae", "Simuliidae", "Tabanidae", "Tipulidae"]
Samples per family:
Asilidae: 8
Bibionidae: 6
Ceratopogonidae: 8
Chironomidae: 8
Rhagionidae: 4
Sciaridae: 6
Simuliidae: 7
Tabanidae: 11
Tipulidae: 12
1 Introduction
The order Diptera (true flies) comprises over 150,000 described species across more than 150 families. Wing venation patterns are a classical diagnostic character in Diptera systematics: the arrangement, branching and connectivity of veins varies markedly across families and provides a natural morphological signature.
In this work, we apply Topological Data Analysis (TDA) to the problem of classifying Diptera families from wing images. TDA provides a framework for extracting shape descriptors that are robust to continuous deformations — exactly the kind of invariance desirable when comparing biological structures that vary in scale, orientation and minor deformations across individuals.
We employ two complementary filtration strategies:
- Vietoris-Rips filtration on point-cloud samples of wing silhouettes — captures global loop structure
- Radial filtration from the wing centroid to the periphery — captures how vein topology is organized from center outward
For each filtration, we compute both H0 (connected components / vein branching) and H1 (loops / enclosed cells) persistence, then extract extended summary statistics (19 interpretable features per diagram) and classify using simple, explainable models (LDA, Decision Trees, Random Forests). The goal is to find interpretable topological criteria for family identification.
We initially tested five filtration strategies including directional height filtrations (8 directions), Euclidean Distance Transform (EDT), and grayscale cubical filtrations. However: (a) directional filtrations are noise-sensitive — in images with isolated pixels and incomplete vein segmentation, each sweep direction creates spurious topological features; (b) EDT produces trivial persistence on binarized images where veins are ~1 pixel wide; (c) cubical (grayscale) filtrations are meaningless on already-binarized black-and-white images. See NOTES.md for details on discarded methods.
2 Methods
2.1 Data loading and preprocessing
All images are in the images/processed directory. For each image, we load it, apply a Gaussian blur (to close small gaps in the wing membrane and keep it connected), crop to the bounding box, and resize to 150 pixels of height.
2.1.1 Excluding small families
Families with fewer than 3 samples (e.g. Pelecorhynchidae with \(n=2\)) can distort cross-validation results—a single misclassification changes accuracy by 50%. We provide a filtered version and run the analysis both ways.
Filtered dataset: 70 samples, 9 families
2.2 Example: forcing connectivity on 5 wings
The chunk below selects 5 wings (prioritizing those with the largest number of disconnected components before correction), then compares the binary pixel set before and after connect_pixel_components.
| Row | sample | n_components_before | n_components_after | n_pixels_before | n_pixels_after |
|---|---|---|---|---|---|
| String | Int64 | Int64 | Int64 | Int64 | |
| 1 | simulidae 27 | 101 | 1 | 9233 | 9568 |
| 2 | biobionidae 9 | 88 | 1 | 9425 | 9605 |
| 3 | simulidae 26 | 80 | 1 | 11556 | 11778 |
| 4 | chironomidae 19 | 75 | 1 | 11504 | 11763 |
| 5 | simulidae 24 | 71 | 1 | 9019 | 9189 |
3 Topological feature extraction
We compute persistent homology using two filtration strategies. For the Vietoris-Rips filtration on connected point clouds, H0 is uninformative (single infinite bar), so we use only H1. For the radial filtration (computed via sublevel-set persistence on the pixel grid), H0 is highly informative — it captures when disconnected vein segments merge as the filtration parameter grows, directly encoding vein count and branching patterns. We therefore compute both H0 and H1 for the radial filtration.
Persistent homology is the main tool of TDA. Given a shape or dataset, it tracks how topological features — connected components (dimension 0), loops (dimension 1), voids (dimension 2), etc. — appear and disappear as we “grow” the shape through a filtration parameter. Each feature has a birth time (when it appears) and a death time (when it gets filled in). The collection of all (birth, death) pairs is called a persistence diagram. Features with long lifetimes (high persistence = death \(-\) birth) represent genuine topological structure, while short-lived features are typically noise.
3.1 Strategy 1: Vietoris-Rips filtration on point clouds
Given a set of points in \(\mathbb{R}^n\), the Vietoris-Rips complex at scale \(\varepsilon\) connects any subset of points that are pairwise within distance \(\varepsilon\). As \(\varepsilon\) increases from 0, we obtain a nested sequence of simplicial complexes — the Rips filtration. This is the most common filtration in TDA for point-cloud data. It is computationally expensive (since it must consider all pairwise distances), which is why we subsample the point clouds.
We sample 750 points from each wing silhouette using farthest-point sampling (which ensures good coverage of the shape), then compute 1-dimensional Rips persistence:
70-element Vector{Matrix{Float64}}:
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
⋮
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
[1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; … ; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813; 1.0000000074505813 1.0000000074505813 … 1.0000000074505813 1.0000000074505813]
3.2 Strategy 2: Radial filtration
The radial filtration assigns each foreground pixel a value equal to its distance from the centroid of the wing. Sublevel-set persistence on this function captures how topological features (loops in the venation) are distributed from the center of the wing outward. This is complementary to the Rips filtration, which captures global loop structure without spatial information.
We also compute H0 persistence for the radial filtration, capturing how disconnected vein segments merge as the radial sweep grows outward:
3.3 Visualizing the radial filtration
The radial filtration assigns each foreground pixel a value proportional to its distance from the wing centroid. Below we visualize the radial filtration arrays and the resulting persistence diagrams for one wing per family:
3.4 Examples: persistence diagrams from each strategy
Below we show persistence diagrams from both Rips and radial filtrations for one specimen per family:
3.5 Extended summary statistics
We extract 19 summary statistics from each persistence diagram using pd_statistics_extended:
- Count of intervals, max/total/total² persistence
- Quantiles (10th, 25th, 50th, 75th, 90th)
- Entropy, std of persistence
- Skewness, kurtosis of persistence distribution
- Median birth, median death, std birth, std death
- Mean midlife = mean of (birth + death)/2
- Persistence range = max - min persistence
Statistics per diagram: 19 features
Rips H1: (70, 19)
Radial H1: (70, 19)
Radial H0: (70, 19)
3.5.1 Statistics comparison by family
4 Classification
We build the feature matrix from the extended summary statistics of both filtrations:
Feature matrix: (70, 57)
57 features × 70 samples
Feature-to-sample ratio: 0.81
With only 72 samples, we use leave-one-out cross-validation: for each sample, the classifier is trained on all other samples and tested on the held-out one. LOOCV has low bias (nearly the entire dataset is used for training) and is the standard validation strategy for small datasets.
4.1 Decision tree
We use a single decision tree as our most interpretable classifier. The tree structure itself provides readable classification rules:
| Row | max_depth | min_samples_leaf | n_correct | accuracy | balanced_accuracy | macro_f1 |
|---|---|---|---|---|---|---|
| Int64 | Int64 | Int64 | Float64 | Float64 | Float64 | |
| 1 | 5 | 2 | 37 | 0.528571 | 0.54305 | 0.526573 |
| 2 | 5 | 3 | 36 | 0.514286 | 0.532949 | 0.512004 |
| 3 | 6 | 2 | 36 | 0.514286 | 0.529161 | 0.5107 |
| 4 | 6 | 3 | 36 | 0.514286 | 0.532949 | 0.512004 |
| 5 | 8 | 2 | 36 | 0.514286 | 0.529161 | 0.5107 |
| 6 | 8 | 3 | 36 | 0.514286 | 0.532949 | 0.512004 |
| 7 | 5 | 1 | 35 | 0.5 | 0.515272 | 0.500981 |
| 8 | 6 | 1 | 34 | 0.485714 | 0.501383 | 0.484701 |
| 9 | 8 | 1 | 34 | 0.485714 | 0.501383 | 0.485786 |
| 10 | 4 | 2 | 30 | 0.428571 | 0.456229 | 0.406526 |
Best Decision Tree LOOCV: 37/70 (52.9%)
Balanced accuracy: 54.3%
| Row | feature | importance |
|---|---|---|
| String | Float64 | |
| 1 | Rips_H1__entropy | 0.235118 |
| 2 | Rips_H1__q10 | 0.136255 |
| 3 | Radial_H0__entropy | 0.122901 |
| 4 | Rips_H1__median_birth | 0.105657 |
| 5 | Radial_H0__total_pers | 0.104808 |
| 6 | Radial_H0__pers_range | 0.0826186 |
| 7 | Rips_H1__skewness | 0.0815281 |
| 8 | Radial_H0__q10 | 0.0752096 |
| 9 | Rips_H1__max_pers | 0.0152865 |
| 10 | Rips_H1__std_death | 0.0137579 |
| 11 | Radial_H0__count | 0.0137579 |
| 12 | Radial_H0__median | 0.0131027 |
Decision tree structure:
Feature 10: "Rips_H1__entropy" < 2.347 ?
├─ Feature 48: "Radial_H0__entropy" < 4.424 ?
├─ Feature 41: "Radial_H0__total_pers" < 25.63 ?
├─ Feature 17: "Rips_H1__std_death" < 13.62 ?
├─ Simuliidae : 6/6
└─ Sciaridae : 1/2
└─ Feature 14: "Rips_H1__median_birth" < 7.999 ?
├─ Feature 12: "Rips_H1__skewness" < -0.04769 ?
├─ Sciaridae : 5/5
└─ Bibionidae : 4/4
└─ Feature 39: "Radial_H0__count" < 156.0 ?
├─ Chironomidae : 6/6
└─ Chironomidae : 1/2
└─ Feature 14: "Rips_H1__median_birth" < 7.713 ?
├─ Ceratopogonidae : 1/2
└─ Ceratopogonidae : 7/7
└─ Feature 5: "Rips_H1__q10" < 7.187 ?
├─ Feature 57: "Radial_H0__pers_range" < 1.804 ?
├─ Feature 45: "Radial_H0__median" < 0.001287 ?
├─ Asilidae : 1/2
└─ Asilidae : 5/5
└─ Feature 43: "Radial_H0__q10" < 0.0003789 ?
├─ Feature 10: "Rips_H1__entropy" < 2.463 ?
├─ Asilidae : 1/2
└─ Tipulidae : 10/10
└─ Rhagionidae : 3/3
└─ Feature 10: "Rips_H1__entropy" < 2.593 ?
├─ Rhagionidae : 1/2
└─ Feature 2: "Rips_H1__max_pers" < 39.98 ?
├─ Tabanidae : 10/10
└─ Asilidae : 1/2
4.2 LDA (Linear Discriminant Analysis)
LDA finds a linear projection of the feature space that maximizes the ratio of between-class variance to within-class variance. The projected data is then classified with a simple 1-NN rule. LDA is a classical method that works well when classes are approximately Gaussian and the number of features is not too large relative to the number of samples.
LDA LOOCV: 46/70 (65.7%)
Balanced accuracy: 65.4%
Macro-F1: 64.3%
4.3 Balanced Random Forest
A Random Forest is an ensemble of decision trees, each trained on a bootstrap sample of the data using a random subset of features. The final prediction is the majority vote across all trees. Balanced Random Forests oversample minority classes (or weight them inversely to their frequency) so that rare families are not drowned out by common ones — important here because Tipulidae has 12 samples while some families have only 2–3. Random Forests are robust to overfitting, handle high-dimensional features well, and provide built-in feature importance estimates.
| Row | n_trees | max_depth | min_leaf | n_correct | accuracy | balanced_accuracy | macro_f1 |
|---|---|---|---|---|---|---|---|
| Int64 | Int64 | Int64 | Int64 | Float64 | Float64 | Float64 | |
| 1 | 200 | -1 | 1 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 2 | 200 | -1 | 2 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 3 | 200 | 8 | 1 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 4 | 200 | 8 | 2 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 5 | 200 | 12 | 1 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 6 | 200 | 12 | 2 | 52 | 0.742857 | 0.739899 | 0.726137 |
| 7 | 1000 | -1 | 1 | 52 | 0.742857 | 0.739899 | 0.722776 |
| 8 | 1000 | -1 | 2 | 52 | 0.742857 | 0.739899 | 0.722776 |
Best Balanced RF LOOCV: 52/70 (74.3%)
n_trees=200
Balanced accuracy: 74.0%
Macro-F1: 72.6%
4.4 SVM
An SVM finds the hyperplane that maximizes the margin between classes. The RBF (Radial Basis Function) kernel maps data into a high-dimensional space where linear separation becomes possible, controlled by a regularization parameter \(C\) (penalty for misclassification): small \(C\) allows wider margins with more misclassifications, large \(C\) enforces tight boundaries. The linear kernel finds a separating hyperplane directly in the original feature space and is less prone to overfitting when \(p \gg n\).
| Row | method | n_correct | n_total | accuracy | balanced_accuracy | macro_f1 |
|---|---|---|---|---|---|---|
| String | Int64 | Int64 | Float64 | Float64 | Float64 | |
| 1 | SVM (Linear, C=0.1) | 48 | 70 | 0.685714 | 0.645623 | 0.640102 |
| 2 | SVM (Linear, C=1.0) | 46 | 70 | 0.657143 | 0.626263 | 0.627028 |
| 3 | SVM (Linear, C=10.0) | 46 | 70 | 0.657143 | 0.626263 | 0.627028 |
| 4 | SVM (Linear, C=100.0) | 46 | 70 | 0.657143 | 0.626263 | 0.627028 |
| 5 | SVM (RBF, C=10.0) | 44 | 70 | 0.628571 | 0.598485 | 0.5844 |
| 6 | SVM (RBF, C=100.0) | 44 | 70 | 0.628571 | 0.598485 | 0.5844 |
| 7 | SVM (RBF, C=1.0) | 41 | 70 | 0.585714 | 0.526094 | 0.501635 |
| 8 | SVM (Linear, C=0.01) | 39 | 70 | 0.557143 | 0.489899 | 0.469207 |
Best SVM: SVM (Linear, C=0.1)
48/70 (68.6%)
Balanced accuracy: 64.6%
Macro-F1: 64.0%
4.5 k-NN on Rips Wasserstein distance
The Wasserstein distance \(W_q\) between two persistence diagrams is the cost of the optimal matching between their points (including matching points to the diagonal, representing trivial features). With \(q=1\) it equals the Earth Mover’s Distance; with \(q=2\) it penalizes large mismatches more heavily.
k-Nearest Neighbors (k-NN) classifies a query by majority vote among its \(k\) nearest neighbors in the distance matrix. With \(k=1\), this is the simplest possible classifier — completely hyperparameter-free — and serves as a useful baseline.
As a complementary approach, we compute pairwise Wasserstein distances between the Rips H1 persistence diagrams and classify with k-NN. Unlike the feature-based classifiers above, this operates directly on the persistence diagrams without extracting summary statistics, and is therefore less susceptible to information loss during featurization.
| Row | method | n_correct | n_total | accuracy | balanced_accuracy | macro_f1 |
|---|---|---|---|---|---|---|
| String | Int64 | Int64 | Float64 | Float64 | Float64 | |
| 1 | 1-NN Rips Wass-1 | 48 | 70 | 0.685714 | 0.656566 | 0.647072 |
| 2 | 5-NN Rips Wass-2 | 47 | 70 | 0.671429 | 0.638889 | 0.620491 |
| 3 | 3-NN Rips Wass-1 | 46 | 70 | 0.657143 | 0.610269 | 0.589769 |
| 4 | 5-NN Rips Wass-1 | 45 | 70 | 0.642857 | 0.583333 | 0.537277 |
| 5 | 1-NN Rips Wass-2 | 44 | 70 | 0.628571 | 0.587121 | 0.579056 |
| 6 | 3-NN Rips Wass-2 | 44 | 70 | 0.628571 | 0.58165 | 0.553934 |
4.6 Summary of all classifiers
| Row | method | n_correct | n_total | accuracy | balanced_accuracy |
|---|---|---|---|---|---|
| String | Int64 | Int64 | Float64 | Float64 | |
| 1 | Balanced RF (T=200) | 52 | 70 | 0.742857 | 0.739899 |
| 2 | SVM (Linear, C=0.1) | 48 | 70 | 0.685714 | 0.645623 |
| 3 | 1-NN Rips Wass-1 | 48 | 70 | 0.685714 | 0.656566 |
| 4 | 5-NN Rips Wass-2 | 47 | 70 | 0.671429 | 0.638889 |
| 5 | LDA | 46 | 70 | 0.657143 | 0.65374 |
| 6 | Decision Tree (d=5) | 37 | 70 | 0.528571 | 0.54305 |
5 Which features drive the classification?
| Row | feature | importance |
|---|---|---|
| String | Float64 | |
| 1 | Rips_H1__entropy | 1.0 |
| 2 | Rips_H1__total_pers | 0.949461 |
| 3 | Radial_H0__count | 0.926215 |
| 4 | Radial_H0__entropy | 0.907955 |
| 5 | Rips_H1__max_pers | 0.835533 |
| 6 | Radial_H0__total_pers | 0.798282 |
| 7 | Rips_H1__median_birth | 0.795691 |
| 8 | Rips_H1__total_pers2 | 0.733267 |
| 9 | Radial_H0__std_birth | 0.726678 |
| 10 | Radial_H0__total_pers2 | 0.670079 |
| 11 | Rips_H1__q90 | 0.621246 |
| 12 | Rips_H1__q75 | 0.619905 |
| 13 | Radial_H0__q25 | 0.610705 |
| 14 | Rips_H1__count | 0.602051 |
| 15 | Radial_H0__q10 | 0.598654 |
| 16 | Rips_H1__std_death | 0.596886 |
| 17 | Rips_H1__std_pers | 0.574682 |
| 18 | Rips_H1__pers_range | 0.512191 |
| 19 | Rips_H1__q10 | 0.474335 |
| 20 | Radial_H0__median_birth | 0.472743 |
6 Feature ablation: Rips vs Radial
| Row | filtrations | n_features | lda_correct | lda_accuracy | rf_correct | rf_accuracy |
|---|---|---|---|---|---|---|
| String | Int64 | Int64 | Float64 | Int64 | Float64 | |
| 1 | Rips + Radial H0 | 38 | 49 | 70.0 | 51 | 72.9 |
| 2 | Rips + Radial H0+H1 (all) | 57 | 46 | 65.7 | 51 | 72.9 |
| 3 | Radial H0 only | 19 | 43 | 61.4 | 40 | 57.1 |
| 4 | Rips + Radial H1 | 38 | 41 | 58.6 | 47 | 67.1 |
| 5 | Radial H0 + H1 | 38 | 40 | 57.1 | 41 | 58.6 |
| 6 | Rips H1 only | 19 | 37 | 52.9 | 45 | 64.3 |
| 7 | Radial H1 only | 19 | 10 | 14.3 | 16 | 22.9 |
7 Honest evaluation (Nested LOOCV)
Standard LOOCV can give optimistically biased estimates when hyperparameters are tuned on the same data. Nested LOOCV adds an inner cross-validation loop: for each held-out test sample, the best hyperparameters are selected using only the training fold. This provides an unbiased estimate of generalization performance.
=== Nested LOOCV: Balanced RF ===
Features: 57 (Rips + Radial stats)
Accuracy: 44/70 (62.9%)
Balanced accuracy: 62.7%
Macro-F1: 61.1%
95% Wilson CI: [51.1%, 73.2%]
7.1 Confusion matrix
Per-class accuracy (Nested LOOCV):
Asilidae: 5/8 (62.5%)
Bibionidae: 5/6 (83.3%)
Ceratopogonidae: 7/8 (87.5%)
Chironomidae: 2/8 (25.0%)
Rhagionidae: 1/4 (25.0%)
Sciaridae: 4/6 (66.7%)
Simuliidae: 7/7 (100.0%)
Tabanidae: 8/11 (72.7%)
Tipulidae: 5/12 (41.7%)
7.2 Confidence interval for best classifier
=== Best Method ===
Balanced RF (T=200): 52/70 (74.3%)
95% Wilson CI: [63.0%, 83.1%]
8 Discussion
We applied two TDA filtration strategies — Vietoris-Rips and radial — to classify Diptera families from wing venation images, extracting 19 extended summary statistics per persistence diagram.
8.1 Key findings
Two filtrations capture complementary information: The Vietoris-Rips filtration on point-cloud samples captures the global loop structure of the wing venation (number and prominence of wing cells). The radial filtration captures the center-to-periphery organization: how veins and cells are arranged spatially from the wing base outward.
Extended summary statistics are sufficient: The 19-feature extended statistics (count, max/total persistence, quantiles, entropy, skewness, kurtosis, median birth/death, etc.) capture the essential information from each persistence diagram. With 3 diagrams × 19 features = 57 total features for 72 samples, the feature-to-sample ratio stays reasonable (~0.8:1), reducing overfitting risk.
Feature ablation reveals which filtrations matter: The ablation study shows whether Rips alone, radial alone, or the combination gives the best performance. This provides evidence about whether global topology (Rips) or spatial organization (radial) is more discriminative.
Why other filtrations were dropped:
- Directional (height) filtrations: 8 sweep directions × H0+H1 produced a large feature set dominated by noise. On noisy binarized images with isolated pixels and incomplete segmentation, each sweep direction generates spurious topological features.
- EDT (Euclidean Distance Transform): On binarized images, the EDT is trivially related to the binary structure, providing little additional information beyond what Rips already captures.
- Cubical (grayscale sublevel-set): After binarization, the grayscale information is lost, so cubical persistence reduces to computing persistence on a binary image — equivalent to connected-component analysis.
Nested LOOCV provides honest evaluation: Standard LOOCV can be optimistic when hyperparameters are tuned on the same data. Nested LOOCV (with 4-fold inner CV for hyperparameter selection) gives unbiased accuracy estimates.
Statistical rigor: We report LOOCV accuracy with Wilson confidence intervals, and nested LOOCV for unbiased evaluation.
8.2 Limitations
- Class imbalance: Tipulidae has 12 samples while some families have only 2–3, which affects classifier performance.
- Image quality and preprocessing parameters (blur, threshold) influence topological features.
- With only 72 samples, confidence intervals remain wide regardless of method.
- Wings are manually segmented and binarized; automated segmentation could introduce different error patterns.
8.3 Future work
- Extend dataset with more specimens per family, especially underrepresented ones
- Improve imaging/segmentation quality to reduce noise
- Apply extended persistence or zigzag persistence for richer invariants
- Investigate which specific topological features (e.g., how many loops, persistence of largest features) correspond to known vein characters in Diptera taxonomy
- Try the analysis on non-binarized (grayscale) images, where EDT and cubical filtrations would be more informative
Citation
@online{vituri_f._pinto2026,
author = {Vituri F. Pinto, Guilherme and Ura, Sergio and , Northon},
title = {Diptera Wing Classification Using {Topological} {Data}
{Analysis}},
date = {2026-02-25},
langid = {en},
abstract = {We apply tools from Topological Data Analysis (TDA) to
classify Diptera families based on wing venation patterns. Using two
complementary filtration strategies -\/-\/- Vietoris-Rips on point
clouds and radial filtrations on wing images -\/-\/- we extract both
H0 and H1 topological features via extended summary statistics and
compare classifiers via leave-one-out cross-validation. We focus on
interpretable models (LDA, Decision Trees) to identify explainable
topological criteria that distinguish families.}
}